home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / lsearch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  883 b   |  52 lines

  1. #include "lib.h"
  2.  
  3. /*  lsearch(3)  and  lfind(3)
  4.  *
  5.  *  Author: Terrence W. Holm          Sep. 1988
  6.  */
  7.  
  8. #ifndef NULL
  9. #define  NULL  (char *) 0
  10. #endif
  11.  
  12. char *lsearch( key, base, count, width, keycmp )
  13.   char *key;
  14.   char *base;
  15.   unsigned *count;
  16.   unsigned  width;
  17.   int  (*keycmp)(char *, char *);
  18.  
  19.   {
  20.   char *entry;
  21.   char *last = base + *count * width;
  22.  
  23.   for ( entry = base;  entry < last;  entry += width )
  24.     if ( keycmp( key, entry ) == 0 )
  25.     return( entry );
  26.  
  27.   bcopy( key, last, (long)width );
  28.   *count += 1;
  29.   return( last );
  30.   }
  31.  
  32.  
  33.  
  34. char *lfind( key, base, count, width, keycmp )
  35.   char *key;
  36.   char *base;
  37.   unsigned *count;
  38.   unsigned  width;
  39.   int  (*keycmp)(char *, char *);
  40.  
  41.   {
  42.   char *entry;
  43.   char *last = base + *count * width;
  44.  
  45.   for ( entry = base;  entry < last;  entry += width )
  46.     if ( keycmp( key, entry ) == 0 )
  47.     return( entry );
  48.  
  49.   return( NULL );
  50.   }
  51.  
  52.